package com.eleadmin.order.service.impl;

import com.eleadmin.common.core.web.JsonResult;
import com.eleadmin.common.system.entity.User;
import com.eleadmin.damon.utils.results.PageResult2;
import com.eleadmin.damon.utils.utils.PinyinUtils;
import com.eleadmin.order.entity.CustomerFactory;
import com.eleadmin.order.service.CustomerFactoryService;
import org.springframework.stereotype.Service;
import com.eleadmin.order.biz.CustomerFactoryBiz;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;


/**
 * 工厂地址服务实现类
 * @author : Doman
 * @date : 2023-03-01 16:34:52
 * @version ：1.0
 */
@Service
public class CustomerFactoryServiceImpl /*extends ServiceImpl<CustomerFactoryMapper, CustomerFactory> */implements CustomerFactoryService {

    @Autowired
    private CustomerFactoryBiz customerFactoryBiz;

    @Override
    public JsonResult list(PageResult2<T> page, CustomerFactory customerFactory, User loginUser)  throws Exception{
        return customerFactoryBiz.list(page,customerFactory,loginUser);
    }

    @Override
    public JsonResult list(CustomerFactory customerFactory, User loginUser) {
        return JsonResult.ok().setData(customerFactoryBiz.list(customerFactory,loginUser));
    }

    @Override
    public JsonResult getById(String id) {
        return JsonResult.ok().setData(customerFactoryBiz.getById(id));
    }

    @Transactional
    @Override
    public JsonResult save(CustomerFactory customerFactory, User loginUser) {
        if (customerFactoryBiz.save(customerFactory, loginUser)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }

    @Transactional
    @Override
    public JsonResult update(CustomerFactory customerFactory, User loginUser) {
        if (customerFactory.getFstate().equals("默认地址")) {
            customerFactoryBiz.updateFstate(customerFactory, loginUser);
        }
        PinyinUtils.ToPinyin(customerFactory.getFaddress());
        if (customerFactoryBiz.update(customerFactory, loginUser)) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }

    @Transactional
    @Override
    public JsonResult remove(String id, User loginUser) {
        if (customerFactoryBiz.remove(id, loginUser)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }

}
